home *** CD-ROM | disk | FTP | other *** search
- --------------------------------------------------------------------------------
- -- Weapon Crossbow + Projectile Bolt
- -- Original Carnage Contest Weapon
- -- Script by DC, August 2009, www.UnrealSoftware.de
- --------------------------------------------------------------------------------
-
- -- Setup Tables
- if cc==nil then cc={} end
- cc.crossbow={}
- cc.crossbow.bolt={}
-
- -- Load & Prepare Ressources
- cc.crossbow.gfx_wpn=loadgfx("weapons/crossbow.bmp") -- Weapon Image
- setmidhandle(cc.crossbow.gfx_wpn)
- cc.crossbow.gfx_icon=loadgfx("weapons/crossbowicon.bmp") -- Weapon Icon
- setmidhandle(cc.crossbow.gfx_icon)
- cc.crossbow.gfx_pro=loadgfx("weapons/bolt.bmp") -- Projectile Image
- setmidhandle(cc.crossbow.gfx_pro)
- cc.crossbow.sfx_attack=loadsfx("arrow_shoot.ogg") -- Attack Sound
- cc.crossbow.sfx_impact=loadsfx("arrow_impact.ogg") -- Impact Sound
-
- --------------------------------------------------------------------------------
- -- Weapon: Crossbow
- --------------------------------------------------------------------------------
-
- cc.crossbow.id=addweapon("cc.crossbow","Crossbow",cc.crossbow.gfx_icon,1) -- Add Weapon (1 use)
- cc.crossbow.ammo=10 -- 10 bolts
-
- function cc.crossbow.draw() -- Draw
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- drawinhand(cc.crossbow.gfx_wpn,6,0)
- -- HUD ammobar
- if cc.crossbow.ammo-weapon_shots>0 then
- hudammobar(cc.crossbow.ammo-weapon_shots,cc.crossbow.ammo)
- end
- -- HUD Crosshair
- if cc.crossbow.ammo-weapon_shots>0 then
- hudcrosshair(7,3)
- end
- end
-
- function cc.crossbow.attack(attack) -- Attack
- -- Decrement timer
- if weapon_timer>0 then
- weapon_timer=weapon_timer-1
- end
- -- Attack
- if weapon_shots<cc.crossbow.ammo and weapon_timer<=0 and attack==1 then
- -- No more weapon switching!
- useweapon(0)
- -- Reset Timer
- weapon_timer=25
- -- Attack
- playsound(cc.crossbow.sfx_attack)
- weapon_shots=weapon_shots+1
- id=createprojectile(cc.crossbow.bolt.id)
- projectiles[id]={}
- -- Ignore collision with current player at beginning
- projectiles[id].ignore=playercurrent()
- -- Set initial position of projectile
- projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
- projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
- -- Set speed of projectile
- projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*14.0
- projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*14.0
- -- Initial movement
- projectiles[id].x=projectiles[id].x-projectiles[id].sx*0.3
- projectiles[id].y=projectiles[id].y-projectiles[id].sy*0.3
- for i=1,1,1 do
- if cc.crossbow.bolt.move(id)==1 then
- break
- end
- end
- -- Effects
- recoil(3)
- -- End Turn
- if (weapon_shots>=cc.crossbow.ammo) then
- endturn()
- end
- end
- end
-
- --------------------------------------------------------------------------------
- -- Projectile: Bolt
- --------------------------------------------------------------------------------
-
- cc.crossbow.bolt.id=addprojectile("cc.crossbow.bolt") -- Add Projectile
-
- function cc.crossbow.bolt.draw(id) -- Draw
- -- Setup draw mode
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- setscale(1,1)
- -- Calculate projectile rotation
- setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
- -- Draw projectile
- drawimage(cc.crossbow.gfx_pro,projectiles[id].x,projectiles[id].y)
- -- Draw arrow if out of Screen
- outofscreenarrow(projectiles[id].x,projectiles[id].y)
- end
-
- function cc.crossbow.bolt.update(id) -- Update
- -- Wind + Gravity influence on speed
- projectiles[id].sx=projectiles[id].sx+getwind()*0.1
- projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
- -- Move
- cc.crossbow.bolt.move(id)
- end
-
- function cc.crossbow.bolt.move(id)
- rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
- -- Move (in substep loop for optimal collision precision)
- msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/2)
- msubx=projectiles[id].sx/msubt
- msuby=projectiles[id].sy/msubt
- for i=1,msubt,1 do
- projectiles[id].x=projectiles[id].x+msubx
- projectiles[id].y=projectiles[id].y+msuby
- -- Collision
- if collision(col2x2,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)==1 then
- if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
- if playercollision()~=0 then
- -- Cause Player damage
- playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
- playerdamage(playercollision(),3)
- blood(projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)
- playsound(sfx_splatter3)
- elseif objectcollision()>0 then
- -- Cause Object damage
- objectdamage(objectcollision(),3)
- else
- -- Draw bolt in terrain
- terrainimage(cc.crossbow.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
- end
- -- Effects
- playsound(cc.crossbow.sfx_impact)
- particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)
- particlefadealpha(0.006)
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- else
- projectiles[id].ignore=0
- end
- -- Water
- if (projectiles[id].y)>getwatery()+5 then
- -- Effects
- particle(p_waterhit,projectiles[id].x,projectiles[id].y)
- if math.random(1,2)==1 then
- playsound(sfx_hitwater2)
- else
- playsound(sfx_hitwater3)
- end
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- end
- end